package cn.com.dcsgo.service.impl;

import cn.com.dcsgo.ProductFeignClient;
import cn.com.dcsgo.UserFeignClient;
import cn.com.dcsgo.SearchFeignClient;
import cn.com.dcsgo.model.product.Category;
import cn.com.dcsgo.model.product.SkuInfo;
import cn.com.dcsgo.model.search.SkuEs;
import cn.com.dcsgo.service.HomeService;
import cn.com.dcsgo.vo.user.LeaderAddressVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * HomeServiceImpl
 *
 * @author Dcsgo
 * @since 2025/4/24 20:46
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {
    private final UserFeignClient userFeignClient;
    private final ProductFeignClient productFeignClient;
    private final SearchFeignClient searchFeignClient;

    @Override
    public Map<String, Object> getIndexDataByUserId(Long userId) {
        Map<String, Object> result = new HashMap<>();

        //获取默认自提点信息 远程调用用户接口
        log.debug("userId:{}", userId);
        LeaderAddressVo defaultDeliveryAddress = userFeignClient.getDefaultDeliveryAddressByUserId(userId);
        result.put("leaderAddressVo", defaultDeliveryAddress);

        //获取所有商品分类信息 远程调用商品接口
        List<Category> categoryList = productFeignClient.getAllCategory();
        result.put("categoryList", categoryList);

        //获取新人专享商品信息 远程调用商品接口
        List<SkuInfo> newPersonSkuInfoList = productFeignClient.getSkuInfoByCountForNewUser(3);
        result.put("newPersonSkuInfoList", newPersonSkuInfoList);

        //获取热门商品信息 远程调用 ES 接口
        List<SkuEs> hotSkuList = searchFeignClient.getEsHotSkuInfoByCount(10);
        result.put("hotSkuList", hotSkuList);

        return result;
    }
}
